<template>
  <Table
    ref="tableRef"
    :url="URL_PAGINGFTP"
    :columns="data.columns"
    :handles="data.handles"
    :toolbar="data.toolbar"
    :query="data.query"
  ></Table>
</template>

<script lang="ts" setup name="firmwareVersionList">
import Table from '@/components/table/index.vue';
import { URL_PAGINGFTP } from '@/service/apis/config';
import { queryDicByParent } from '@/service/apis/api';

const router = useRouter();
const tableRef = ref();

const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  columns: [
    {
      prop: 'version',
      label: '版本号',
    },
    {
      prop: 'chargingPileType',
      label: '充电桩类型',
      dic: [] as any,
      type: Number,
    },
    {
      prop: 'ftpAddress',
      label: 'FTP服务器地址',
    },
    {
      prop: 'ftpPort',
      label: 'FTP服务器端口',
    },
    {
      prop: 'downloadTimeout',
      label: '下载超时时间',
    },
    {
      prop: 'updateTime',
      label: '修改时间',
    },
  ],
  handles: [
    {
      label: '修改',
      permission: 'firmwareVersionList.edit',
      handle: (row: any) => {
        router.push({
          name: 'firmwareVersionEdit',
          query: { id: row.id },
        });
      },
    },
  ],
  toolbar: [
    {
      label: '新增',
      permission: 'firmwareVersionList.add',
      icon: 'icon-add',
      type: 'primary',
      handle: (row: any) => {
        router.push({
          name: 'firmwareVersionAdd',
        });
      },
    },
  ],
  query: [
    {
      label: '版本号',
      prop: 'version',
      comName: 'input',
      props: {
        placeholder: '请输入版本号',
      },
    },
    {
      label: '充电桩类型',
      prop: 'chargingPileType',
      comName: 'select',
      props: {
        placeholder: '请选择充电桩类型',
        options: [] as any,
      },
    },
    {
      label: '修改时间',
      prop: 'date',
      comName: 'date',
      keys: ['ftpStartTime', 'ftpEndTime'],
      props: {
        type: 'daterange',
      },
    },
  ],
});
queryDicByParent({
  listDtos: ['chargingPileType'],
}).then((res: any) => {
  if (res) {
    data.query[1].props.options = [...res.chargingPileType];
    data.columns[1].dic = [...res.chargingPileType];
  }
});
</script>